package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.ZJCReturnVisit;
import com.itheima.service.ZJCReturnvisitService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/returnvisit")
public class ZJCReturnvisitController {
    @Reference
    private ZJCReturnvisitService zjcReturnvisitService;

    @RequestMapping("/findByCondition")
    public PageResult findByCondition(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = zjcReturnvisitService.findByCondition(queryPageBean);
        return pageResult;
    }

    @RequestMapping("/add")
    public Result add(@RequestBody ZJCReturnVisit zjcReturnVisit){
        try {
            zjcReturnvisitService.add(zjcReturnVisit);
            return new Result(true,"添加访问记录成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"添加访问记录失败");
        }
    }

    @RequestMapping("/edit")
    public Result edit(@RequestBody ZJCReturnVisit zjcReturnVisit){
        try {
            zjcReturnvisitService.edit(zjcReturnVisit);
            return new Result(true,"编辑访问记录成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"编辑访问记录失败");
        }
    }

    @RequestMapping("/delete")
    public Result delete(Integer id){
        try {
            zjcReturnvisitService.delete(id);
            return new Result(true,"删除访问记录成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"删除访问记录失败");
        }
    }
}
